home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_asm / hercbios / graph.asm < prev    next >
Encoding:
Assembly Source File  |  1979-12-31  |  4.7 KB  |  134 lines

  1.  
  2. ;*******************************************************
  3. ;*
  4. ;*     SET OF GRAPHICS ROUTINES FOR HERCULES BIOS
  5. ;*
  6. ;*             Dave Tutelman - 8/86
  7. ;*
  8. ;*-------------------------------------------------------
  9. ;*
  10. ;*     do_pixel:       draws, erases, or reads a pixel, given an
  11. ;*                     offset and mask.
  12. ;*
  13. ;**********************************************************
  14. ;
  15. INCLUDE        hercbios.h
  16.  
  17. ;------------------------------------------
  18. public wr_pixel,end_herc
  19. extrn  exit_herc_bios:near
  20. ;-----------------------------------------
  21. ;
  22. cseg   segment public
  23.        assume  cs:cseg,ds:bios_data
  24. ;
  25. ;
  26. ;**********************************************
  27. ;*
  28. ;*     read or write a pixel:
  29. ;*             DX = row # ( y )
  30. ;*             CX = col # ( x )
  31. ;*             AH = 12 for write, 13 for read
  32. ;*             AL = value (0,1, if bit 7=1 EXOR the value)
  33. ;*
  34. ;**********************************************
  35. ;
  36. wr_pixel:
  37.        mov     bh,video_mode   ; check for valid mode
  38.        cmp     bh,herc_mode
  39.        je      do_pixel
  40.        cmp     bh,ibm_mode
  41.        je      do_pixel
  42.        jmp     exit_herc_bios          ; invalid mode. don't do it.
  43. ;
  44. do_pixel:
  45.        push    ax              ; save function and pixel value
  46. ;
  47. ;                      ; first compute the address of byte to be modified
  48. ;                      ; = 90*[row/4] + [col/8] + 2^D*[row/4] + 2^F*page
  49.        mov     bh,cl           ; col (low order) in BH
  50.        mov     bl,dl           ; row (low order) in BL
  51.        and     bx,0703H        ; mask the col & row remainders
  52. IFDEF iAPX286
  53.        shr     cx,3            ; col / 8
  54.        shr     dx,2            ; row / 4
  55.        mov     al,90
  56.        mul     dx              ; AX = 90*[ row/4 ]
  57.        add     ax,cx           ;  ... + col/8
  58.        shl     bl,5            ; align row remainder
  59. ELSE                   ; same as above, obscure but fast for 8086
  60.        shr     cx,1            ; divide col by 8
  61.        shr     cx,1
  62.        shr     cx,1
  63.        shr     dx,1            ; divide row by 4
  64.        shr     dx,1
  65.        shl     dx,1            ; begin fast multiply by 90 (1011010 B)
  66.        mov     ax,dx
  67.        shl     dx,1
  68.        shl     dx,1
  69.        add     ax,dx
  70.        shl     dx,1
  71.        add     ax,dx
  72.        shl     dx,1
  73.        shl     dx,1
  74.        add     ax,dx           ; end fast multiply by 90
  75.        add     ax,cx           ; add on the col/8
  76.        shl     bl,1            ; align row remainder
  77.        shl     bl,1
  78.        shl     bl,1
  79.        shl     bl,1
  80.        shl     bl,1
  81. ENDIF
  82.        add     ah,bl           ; use aligned row remainder
  83.        cmp     active_page,0   ; page 0 active?
  84.        je      end_adr_calc    ; yup
  85.        or      ah,80H          ; page 1 active. Set MSB of address
  86. end_adr_calc:          ; address of byte is now in AX
  87. ;
  88.        mov     dx,pixbase      ; base of pixel display to DX
  89.        mov     es,dx           ; ...and thence to segment reg
  90.        mov     si,ax           ; address of byte w/ pixel to index reg
  91.        mov     cl,bh           ; bit addr in byte
  92.        mov     al,80H          ; '1000 0000' in AL
  93.        shr     al,cl           ; shift mask to line up with bit to read/write
  94.        mov     bl,al
  95. ;
  96.        pop     bx              ; now retrieve original AX into BX
  97.                                ;      function=BH, pixel value=BL
  98.        cmp     bh,13           ; what to do with the pixel?
  99.        je      read_pix        ; read the pixel.
  100.        cmp     bl,0            ; write the pixel. But how?
  101.        je      clr_pix         ; clear the pixel
  102.        jl      exor_pix        ; exclusive-or the pixel
  103. ;
  104. set_pix:               ; set the pixel
  105.        or      es:[si],al      ; or the mask with the right byte
  106.        jmp     exit_herc_bios
  107. ;
  108. clr_pix:               ;clear the pixel
  109.        not     al              ; invert the mask, so zero on bit to be cleared
  110.        and     es:[si],al      ; and the mask with the right byte
  111.        jmp     exit_herc_bios
  112. ;
  113. exor_pix:              ; exclusive-or the pixel
  114.        mov     ah,07fH         ; mask to rid 7th bit
  115.        and     ah,bl           ; pixval w/o XOR flag
  116.        jnz     do_exor         ; ExOr with a 1?
  117.        jmp     exit_herc_bios  ; no! XOR (0,x) = x. just return.
  118. do_exor:
  119.        xor     es:[si],al      ; EXOR the pixel with the mask.
  120.        jmp     exit_herc_bios
  121. ;
  122. read_pix:              ; read the pixel
  123.        and     al,es:[si]      ; read the bit into AL
  124.        jz      rd_zro
  125.        mov     al,1            ; if it ain't zero, it's one
  126. rd_zro:        jmp     exit_herc_bios
  127. ;
  128. ;
  129. end_herc:                      ; label for end of package. Used by hercbios
  130.                                ;    to install it.
  131. ;
  132. cseg   ends
  133.        end
  134.